﻿//功能描述：绩效管理：按钮项目考核
using Hong.IRepository.IRepository_AssessmentManagement;
using Hong.Model.SysDomain.Model_AssessmentManagement;
using Hong.Model.SysDomain.Model_AssessmentManagement.ViewAssClassAssSmaliProjec;
using Hong.Repository.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hong.Repository.Repository.Repository_AssessmentManagement
{
   public class AssmentProjectRepository: IAssmentProjectRepository
    {
        #region 构造器注入
        private readonly T_HongShi_3Context _dal;
        public AssmentProjectRepository(T_HongShi_3Context dal)
        {
            _dal = dal;
        }
        #endregion
        #region 项目考核
        #region 大考核项目
        /// <summary>
        /// 大考核项目的显示
        /// </summary>
        /// <returns></returns>
        public List<AssessmentPrjec> GetAssessmentPrjec(string id)
        {
            var list = _dal.AssessmentPrjecs.ToList();
            list = list.Where(x => x.AssPrjectListId == id).ToList();
            return list;
        }
        #endregion

        #region 小考核项目
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="ass"></param>
        /// <returns></returns>
        public int AddAssSmaliProjec(AssSmaliProjec ass)
        {
            var i = _dal.AssSmaliProjecs.Add(ass);
            return _dal.SaveChanges();
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public AssSmaliProjec GetAssSmaliProjecFT(int id)
        {
            var list = _dal.AssSmaliProjecs.FirstOrDefault
                (x => x.PrId == id);
            return list;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int PutAssSmaliProjec(AssSmaliProjec ass)
        {
            _dal.Entry(ass).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _dal.SaveChanges();
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DelAssSmaliProjec(int id)
        {
            var i = _dal.AssSmaliProjecs.Find(id);
            _dal.Remove(i);
            return _dal.SaveChanges();
        }
        /// <summary>
        /// 显示小项目考核
        /// </summary>
        /// <returns></returns>
        public List<ViewAssPrjecSmali> GetViewAssClassSmali(string ids)
        {
            var list2 = _dal.AssessmentPrjecs.ToList();
            var list = _dal.AssSmaliProjecs.ToList();
            list = list.Where(x => x.AssPrjectId == ids).ToList();
            var query = from a in list2
                        join b in list on a.AssPrjectId equals b.AssPrjectId
                        select new ViewAssPrjecSmali
                        {
                            AssPrjectId=a.AssPrjectId,
                            AssPrjectName = a.AssPrjectName,
                            AssPrjectListId = a.AssPrjectListId,
                            AssPrjectPartState = a.AssPrjectPartState,
                            PrId = b.PrId,
                            PrName = b.PrName,
                            PrPerformance = b.PrPerformance,
                            PrNote = b.PrNote,
                            PrFinished = b.PrFinished,
                            PrUnfinished = b.PrUnfinished,
                            PrHistory = b.PrHistory,
                            PrTotal = b.PrTotal,
                        };
            return query.ToList();
        }
        #endregion

        #region 考核分类
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="ass"></param>
        /// <returns></returns>
        public int AddAssClass(AssClass ass)
        {
            var i = _dal.AssClasses.Add(ass);
            return _dal.SaveChanges();
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        public List<ViewAssClasses> GetAssClass(int ids)
        {
            var list1 = _dal.AssClasses.Where(x => x.PrId == ids).ToList();
            var list2 = _dal.Dictionaries.ToList();
            var list = from a in list1
                       join b in list2 on a.ClassTypeId equals b.DicId
                       select new ViewAssClasses
                       {
                           ClassId = a.ClassId,
                           ClassTypeId = a.ClassTypeId,
                           ClassScale = a.ClassScale,
                           ClassDifficulty = a.ClassDifficulty,
                           ClassFictitious = a.ClassFictitious,
                           DicId = b.DicId,
                           DicName = b.DicName,
                           DicCode = b.DicCode,
                           DicDesc = b.DicDesc
                       };
            return list.ToList();
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <returns></returns>
        public AssClass GetAssClassFT(int id)
        {
            var list = _dal.AssClasses.FirstOrDefault(x => x.ClassId == id);
            return list;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <returns></returns>
        public int PutAssClass(AssClass ass)
        {
            _dal.Entry(ass).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _dal.SaveChanges();
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        public int DelAssClass(int id)
        {
            var i = _dal.AssClasses.Find(id);
            _dal.Remove(i);
            return _dal.SaveChanges();
        }
        #endregion
        #endregion

    }
}
